package fi.helsinki.cs.scheduler3000;

/**
 * @author Team TA's
 */


import java.io.Serializable;
import java.util.ArrayList;

import fi.helsinki.cs.scheduler3000.Weekday.Day;

public class Schedule implements Serializable {

	private String period;
	private ArrayList<ArrayList<Event>> eventList;

	// CONSTRUCTORS

	public Schedule(){
		this.setEventList();
		this.period = null;
	}

	public Schedule(String period){
		this.setEventList();
		this.period = period;
	}

	// GETTERS AND SETTERS

	public void setEventList(){
		this.eventList = new ArrayList<ArrayList<Event>>();

		for (int i=0; i<7; i++) {
			eventList.add(new ArrayList<Event>());
		}
	}

	public void setEventList(ArrayList<ArrayList<Event>> newEventList) {
		if (this.eventList == null) {
			setEventList();
		}
		else {
			this.eventList = newEventList;
		}
	}

	public ArrayList<ArrayList<Event>> getEventList(){
		return this.eventList;
	}

	public ArrayList<Event> getEventList(int day){
		return this.eventList.get(day);
	}

	public void setEventList(Schedule newSchedule) {
		this.eventList = newSchedule.getEventList();
		this.period = newSchedule.getPeriod();
	}

	public String getPeriod() {
		return period;
	}

	public void setPeriod(String period) {
		this.period = period;
	}

	// OTHER

	public void addEvent(int eventDay, Event event) {
		if (eventDay >= this.eventList.size() || eventDay < 0) {// if adding an event to non-existent date
			throw new IllegalArgumentException("No such date in the schedule");
		}
		this.eventList.get(eventDay).add(event);
	}
}
